package cn.zktr.Personnel.model.uitls;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

import cn.zktr.Personnel.model.pojos.PerPmsDept;

public class Dept {
	//部门名
	private String deptname;
	//部门人数
	private Integer empsum;
	//创建时间
	private Timestamp depttime;
	//介绍
	private String deptzy;
	//子部门
	private List<Dept> deps;

	public Dept(List<PerPmsDept> list) {
		int em = 0;
		int e = -1;
		for(PerPmsDept ppd : list) {
			if(ppd.getDeptss()==0) {
				setDeptname(ppd.getDeptname());
				setDepttime(ppd.getDepttime());
				setDeptzy(ppd.getDeptzy());
				e = ppd.getDeptid();
			}
			em+=ppd.getPerPmsStms().size();
		}
		setEmpsum(em);
		setDeps(list,e);
	}
	public Dept(List<PerPmsDept> list,PerPmsDept ppd,Integer i) {
		int em = 0;
		int e = -1;
		e = ppd.getDeptid();
		for(PerPmsDept ppd2 : list) {
			if(ppd2.getDeptss()==e || ppd2.getDeptid()==e) {
				em+=ppd2.getPerPmsStms().size();
			}
		}
		setDeptname(ppd.getDeptname());
		setDepttime(ppd.getDepttime());
		setDeptzy(ppd.getDeptzy());
		setEmpsum(em);
		if(e!=-1) {
			setDeps(list,e);
		}
		
	}

	
	
	public Timestamp getDepttime() {
		return depttime;
	}
	public void setDepttime(Timestamp depttime) {
		this.depttime = depttime;
	}
	
	public String getDeptzy() {
		return deptzy;
	}
	public void setDeptzy(String deptzy) {
		this.deptzy = deptzy;
	}

	public String getDeptname() {
		return deptname;
	}

	public void setDeptname(String deptname) {
		this.deptname = deptname;
	}

	public Integer getEmpsum() {
		return empsum;
	}

	public void setEmpsum(Integer empsum) {
		this.empsum = empsum;
	}

	public List<Dept> getDeps() {
		return deps;
	}

	public void setDeps(List<PerPmsDept> list,Integer i) {
		List<Dept> lidt = new ArrayList<>();
		for(PerPmsDept ppd : list) {
			if(ppd.getDeptss()==i) {
				Dept dept = new Dept(list,ppd, i);
				lidt.add(dept);
			}
		}
		this.deps = lidt;
	}
	
	
}
